package Application.UIEditApplication.view
{
	import Application.UIEditApplication.def.Manager;
	
	import fl.core.UIComponent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.geom.Rectangle;
	
	import org.puremvc.as3.patterns.mediator.Mediator;

	public class ViewBaseMed extends Mediator	
	{
		/** 
		 * @param mediatorName  为UI导出类名字
		 */		
		public function ViewBaseMed(mediatorName : String)
		{
			if(mediatorName)
			{
				if(!viewComponent)
				{
					var facadeClass : Class = Manager.Source.getClass(mediatorName);
					
					if(facadeClass)
					{
						viewComponent = new facadeClass as Sprite;
					}
					else
					{
						viewComponent = new Sprite;
					}
				}
			}
			
			super(mediatorName,viewComponent);
		}
		
		public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
		{
			viewSprite.addEventListener(type,listener,useCapture,priority,useWeakReference);
		}
		
		public function dispatchEvent(event:Event):Boolean
		{
			return viewSprite.dispatchEvent(event);;
		}
		
		public function hasEventListener(type:String):Boolean
		{
			return viewSprite.hasEventListener(type);
		}

		public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
		{
			viewSprite.removeEventListener(type,listener,useCapture);
		}
		
		public function willTrigger(type:String):Boolean
		{
			return viewSprite.willTrigger(type);
		}
		
		public function addChild(obj:DisplayObject) : void
		{
			viewSprite.addChild(obj);
		}
		
		public function removeChild(child:DisplayObject) : void
		{
			viewSprite.removeChild(child);
		}
		
		public function startDrag(lockCenter:Boolean = false,bounds:Rectangle = null) : void
		{
			viewSprite.startDrag(lockCenter,bounds);
		}
		
		public function stopDrag():void
		{
			viewSprite.stopDrag();
		}
		
		public function get x() : Number
		{
			return viewSprite.x;
		}
		
		public function set x(value:Number) : void
		{
			viewSprite.x = value;
		}
		
		public function get y() : Number
		{
			return viewSprite.y;
		}
		
		public function set y(value:Number) : void
		{
			viewSprite.y = value;
		}
		
		public function get height() : Number
		{
			return viewSprite.height;
		}
		
		public function set height(value:Number) : void
		{
			viewSprite.height = value;
		}
		
		public function get width() : Number
		{
			return viewSprite.width;
		}
		
		public function set width(value:Number) : void
		{
			viewSprite.width =  value;
		}
		
		public function get graphics() : Graphics
		{
			return viewSprite.graphics;
		}
		
		public function get mouseX() : Number
		{
			return viewSprite.mouseX;
		}
		
		public function get mouseY() : Number
		{
			return viewSprite.mouseY;
		}
		
		public function get parent() : DisplayObjectContainer
		{
			return viewSprite.parent;
		}
		
		public function get viewSprite() : Sprite
		{
			return this.viewComponent as Sprite;
		}
	}
}